<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			/**
			 * @param {number[]} nums1
			 * @param {number[]} nums2
			 * @return {number}
			 */
			//输入：nums1 = [1,3], nums2 = [2]
			//输出：2.00000
			//解释：合并数组 = [1,2,3] ，中位数 2
			// const arr1 = [1, 3];
			// const arr2 = [2];
			function concatArr(nums1, nums2) {
				let arr = [];
				let i = 0,
					j = 0;
				while (i <= nums1.length - 1 && j <= nums2.length - 1) {
					if (nums1[i] <= nums2[j]) {
						arr.push(nums1[i]);
						i++;
					}else{
						arr.push(nums2[j]);
						j++;
					}
				}
				while(i < nums1.length){
					arr.push(nums1[i]);
					i++;
				}
				while(j < nums2.length){
					arr.push(nums2[j]);
					j++;
				}
				return arr;
			}
			var findMedianSortedArrays = function(nums1, nums2) {
				let arr = concatArr(nums1, nums2);
				let n = arr.length;//all arr length
				let z = Math.floor((n-1)/2);
				let r = 0;//value
				if(n % 2 == 0){
					//偶
					r = (arr[z] + arr[z + 1]) / 2;
				}else{
					//奇
					r = arr[z];
				}
				return r;
			};
			console.log(findMedianSortedArrays([1, 3],[2]));
			// console.log(findMedianSortedArrays([0, 0],[0, 0]));
			// console.log(findMedianSortedArrays([1, 2],[3, 4]));
		</script>
	</body>
</html>
